package tema1.weather;

import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;



public class Info extends Activity{


	TextView text, condition, temp_c, humidity,wind_condition;
	TextView[] d=new TextView[4];
	TextView[] c=new TextView[4];
	TextView[] t=new TextView[4];
	ImageView[] i=new ImageView[5];
	String[] data= new String[30];
	@Override
	public void onCreate(Bundle savedInstanceState) 
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.info); 
		text = (TextView) findViewById(R.id.textView1);
		condition = (TextView) findViewById(R.id.textView3);
		temp_c = (TextView) findViewById(R.id.textView2);
		humidity = (TextView) findViewById(R.id.textView4);
		wind_condition =  (TextView) findViewById(R.id.textView5);

		i[0] = (ImageView)findViewById(R.id.imageView1);
		i[1] = (ImageView)findViewById(R.id.imageView2);
		i[2] = (ImageView)findViewById(R.id.imageView3);
		i[3] = (ImageView)findViewById(R.id.imageView4);
		i[4] = (ImageView)findViewById(R.id.imageView5);

		d[0] =(TextView) findViewById(R.id.textView6);
		d[1] =(TextView) findViewById(R.id.textView9);
		d[2] =(TextView) findViewById(R.id.textView12);
		d[3] =(TextView) findViewById(R.id.textView15);

		c[0] =(TextView) findViewById(R.id.textView8);
		c[1] =(TextView) findViewById(R.id.textView11);
		c[2] =(TextView) findViewById(R.id.textView14);
		c[3] =(TextView) findViewById(R.id.textView17);

		t[0] =(TextView) findViewById(R.id.textView7);
		t[1] =(TextView) findViewById(R.id.textView10);
		t[2] =(TextView) findViewById(R.id.textView13);
		t[3] =(TextView) findViewById(R.id.textView16);

		Intent intent = getIntent();
		intent.setClass(this, WeatherActivity.class);
		for(int i=0;i<30;i++)
			data[i] = intent.getStringExtra("c"+i);
		try {
			Bitmap bitmap = BitmapFactory.decodeStream((InputStream)new URL("http://google.com"+data[4]).getContent());
			i[0].setImageBitmap(bitmap); 
		} catch (MalformedURLException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		text.setText("Date: "+data[0]);
		text.setTextColor(Color.GREEN);
		condition.setText("Condition: "+data[1]);
		condition.setTextColor(Color.RED);
		temp_c.setText("Temperature: "+data[2]+" \u2103");
		temp_c.setTextColor(Color.BLUE);
		humidity.setText(data[3]);
		humidity.setTextColor(Color.CYAN);
		wind_condition.setText(data[5]);
		wind_condition.setTextColor(Color.MAGENTA);
		for(int h=1;h<5;h++){
			try {
				Bitmap bitmap = BitmapFactory.decodeStream((InputStream)new URL("http://google.com"+data[13+h]).getContent());
				i[h].setImageBitmap(bitmap); 
			} catch (MalformedURLException e) {
				e.printStackTrace();
			} catch (IOException e) {
				e.printStackTrace();
			}
			d[h-1].setText(data[5+h]);
			c[h-1].setText(data[17+h]);
			t[h-1].setText(" "+data[9+h]+" \u2109"+" \u2192 "+((Integer.parseInt(data[9+h])-32)*5/9)+" \u2103"+"   ");
		}
		

	}


}
